package com.itheima.task;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/*
* (1)写一个Properties格式的配置文件，配置类的完整名称。
	(2) 写一个程序，读取这个Properties配置文件，获得类的完整名称并加载这个类，
	(3)用反射 的方式运行run方法。
* */
public class Demo4 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
      /*  ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        InputStream is = systemClassLoader.getResourceAsStream("prop.properties");

        prop.properties properties = new prop.properties();
        properties.load(is);
        String str = properties.getProperty("className");
        Class clazz = Class.forName(str);
        Object obj = clazz.newInstance();
        Method method = clazz.getMethod("run");
        method.invoke(obj);*/

        Properties properties = new Properties();
        InputStream is = Demo4.class.getClassLoader().getResourceAsStream("prop.properties");
        properties.load(is);

        String className = properties.getProperty("className");
        String methodName = properties.getProperty("methodName");
        Class Clazz = Class.forName(className);
        Object o = Clazz.newInstance();
        Method run1 = Clazz.getMethod(methodName);
        run1.invoke(o);
    }
}
